#pragma once

#include <QMainWindow>
#include <QTemporaryDir>

#include "tasks/taskmanager.h"

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class QProcess;
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    QString CreateTempDir();
    void MountISO();
    void UnMountISO();
    void UnSquashfs();

private slots:
    void OnPushButtonISOClicked();
    void OnPushButtonSaveClicked();
    void OnPushButtonRunClicked();
    void OnLineEditISOEditingFinished();
    void OnLineEditSaveDirEditingFinished();

    void OnTaskQueueAllDone();
    void OnTaskFinished(const TaskData &data, int exit, const QString &errstr = QString());
    void OnTaskError(const TaskData &data, const QString &errstr);
    void OnTaskOutput(const TaskData &data, const QString &outstr);

private:
    Ui::MainWindow *ui;
    TaskManager *mgr;
    QTemporaryDir *tmp;
    QString iso_file;
    QString iso_mount;
    QString save_dir;
};
